﻿//退货单管理 首页
var columns =
            [
                { display: 'Key', name: 'Id', type: 'text', hide: 1 },
                { display: '退货单单号', name: 'ReturnBillNo', mintWidth: 80, width: 120 }, //, type: 'int', mintWidth: 40, width: 100
                {display: '仓库名称', name: 'StorehouseName', mintWidth: 80, width: 140 },
                { display: '送货人', name: 'SenderName', mintWidth: 80, width: 120 },
                { display: '退货人', name: 'ReturnBillorName', mintWidth: 80, width: 120 },
                { display: '收货单位', name: 'orgName', mintWidth: 80, width: 120 },
                { display: '退货时间', name: 'ReturnTime', mintWidth: 180, width: 180, type: 'selfDate' },
                { display: '确认人', name: 'AffirmorName', mintWidth: 80, width: 120 },
                { display: '确认时间', name: 'AffirmDate', mintWidth: 180, width: 180, type: 'selfDate' },
                { display: '确认状态', name: 'AffirmStateName', mintWidth: 100, width: 140 },
                 { display: 'AffirmState', name: 'AffirmState', type: 'int', hide: 1 },
               // { display: '是否结算', name: 'SettleState', mintWidth: 100, width: 140 },
                //{ display: '删除状态', name: 'DeleteState', mintWidth: 80, width: 140 },
                { display: '备注', name: 'Remarks', mintWidth: 80, width: 120 }
             ];

var manager;
//init controls
$(document).ready(function () {
    $("#btnSearch").unbind("click").bind("click", initligerGrid);
    initligerGrid();
    initDataControls();
});

function initligerGrid() {
    manager = null;
    manager = $("#ReturnBillGrid").ligerGrid({
        columns: columns,
        title: '退货单管理',
        showTitle: true,
        width: '100%',
        enabledSort: true,
        height: '99%',
        checkbox: false,
        rownumbers: true,
        toolbar: { items: [ { text: '确认', click: audioOperation, icon: 'modify'}, { line: true },
                                    { text: '查看', click: dialogDetailView, img: '../Content/images/Search.png' }]
        },
        parms: { orgCode: $("#HidOrgCode").val(), HidChengDu: $("#HidChengDu").val(), selectType: "confirm", isConfirm:$("#cbConfirm").val(), billNo: $("#billNo").val(), returnClient: $("#returnClient").val(), StartDate: $("#StartDate").val(), EndDate: $("#EndDate").val(), auditSate: 1 },
        url: "../ReturnBill/GetJsonOfDatas",
        onDblClickRow: function (data, rowindex, rowobj) { viewDetail(data.Id); }
    });
}

function audioOperation() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择要确认的行!'); return; }
    var billId = row["Id"].toString();
    $.ligerDialog.open({ url: "../ReturnBill/Detail?id=" + billId+"&orgCode="+$("#HidOrgCode").val()+"&isConfirm=true", height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false });
}
//审核 
//function audioOperation() {
//    var row = manager.getSelectedRow();
//    if (!row) {
//        $.ligerDialog.success('请选择要确认的行!'); return;
//    }
//    $.ligerDialog.confirm('是否确认？', function (yes) {
//        if (yes) {
//            if (row["AffirmState"].toString() != "1") {
//                $.get("../ReturnBill/Audit?billId=" + row.Id+"&orgCode="+$("#HidOrgCode").val(), {}, function (data) {
//                    if (data != undefined && data == "9") {
//                        $.ligerDialog.success('确认成功!');
//                        initligerGrid();
//                    }
//                });
//            } else {
//                $.ligerDialog.success('已确认过，不能重复确认!');
//            }
//        }
//    });
//}

//
function dialogDetailView() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择要查看的行!'); return; }
    var billId = row["Id"].toString();
    viewDetail(billId);
}
function viewDetail(billId) {
    $.ligerDialog.open({ url: "../ReturnBill/Detail?id=" + billId + "&orgCode=" + $("#HidOrgCode").val() + "&isConfirm=false", height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false });
}




//初始化时间
function initDataControls() {
    $("#StartDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
    $("#EndDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
}